﻿using System.Text.Json.Serialization;

namespace Lib.Data.Entitys; 
/// <summary>
/// 
/// </summary>
internal class PageEntity {
    /// <summary>
    /// 创建对象
    /// </summary>
    public static PageEntity Create(int PageIndex = 1, int PageSize = 10, int Count = 0, string SQL = null) {
        return new PageEntity(PageIndex, PageSize, Count, SQL);
    }
    /// <summary>
    /// 构造函数
    /// </summary>
    public PageEntity(int Page = 1, int PageSize = 10, int Count = 0, string SQL = null) {
        //
        this.Page = Page;
        //
        if (PageSize == 0) {
            this.PageSize = Count;
        } else {
            this.PageSize = PageSize;
            this.PageCount = (Count + PageSize - 1) / PageSize;
        }
        // 
        if (Page < 1) {
            this.Page = 1;
        } else {
            if (Page > this.PageCount) {
                this.Page = this.PageCount;
            } 
        }
        //
        this.Count = Count;
        //
        this.StartRowIndex = (this.Page - 1) * this.PageSize;
        //
        this.EndRowIndex = this.StartRowIndex + this.PageSize;
        //
        this.SQL = SQL;
    }
    /// <summary>
    /// 页码（从 1 开始）
    /// </summary>
    public int Page { get; set; }
    /// <summary>
    /// 每页行数
    /// </summary>
    public int PageSize { get; set; }
    /// <summary>
    /// 分页总数
    /// </summary>
    public int PageCount { get; set; }
    /// <summary>
    /// 总记录数
    /// </summary>
    public int Count { get; set; }
    /// <summary>
    /// 开始行数（从 0 开始）
    /// </summary>
    public int StartRowIndex { get; set; }
    /// <summary>
    /// 结束行数
    /// </summary>
    public int EndRowIndex { get; set; }
    /// <summary>
    /// SQL
    /// </summary>
    public string SQL { get; set; }
    /// <summary>
    /// 数据表名
    /// </summary>
    public string Table { get; set; }
    /// <summary>
    /// 主键名称
    /// </summary>
    public string PrimaryKey{ get; set; }
    /// <summary>
    /// 显示字段列
    /// </summary>
    public string Fields { get; set; }
    /// <summary>
    /// 排序字段列
    /// </summary>
    public string Sorts { get; set; }
    /// <summary>
    /// 查询条件子句
    /// </summary>
    public string Where { get; set; }

}
